package com.gxa.admin.recycling.controller;

import com.gxa.admin.recycling.service.RecycleOrderService;
import com.gxa.core.recycling.common.JsonResult;
import com.gxa.core.recycling.pojo.RecycleOrderShowVo;
import com.gxa.core.recycling.pojo.Recycleorder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
import java.util.Set;

@RestController
@RequestMapping("/recyclingOrder")
@Api(tags = "物资入库管理")
public class RecyclingOrderController {

    @Autowired
    RecycleOrderService recycleOrderService;
    @PostMapping("/findAll")
    @ApiOperation("查询所有订单")
    public Map findAll(@RequestParam("page") Integer page, @RequestParam("size")Integer size,Long id,
                       String userName, Long communityId, String recyclerName,
                        String state, String time
                       ) throws IllegalAccessException {

        JsonResult jsonResult=new JsonResult();
        Map<Integer, List<Map>> recycleOrderByPage = recycleOrderService.findAll(id,communityId,userName,recyclerName,state,time, page, size);

        Set<Integer> integers = recycleOrderByPage.keySet();

        for (Integer integer : integers) {
            jsonResult.setCode("200");
            jsonResult.setData(recycleOrderByPage.get(integer));
            jsonResult.put("total",integer);
        }
        return jsonResult.getDataMap();
    }

    @PostMapping("/findOrderById")
    @ApiOperation("查询单个订单详情")
    public Map findOrderById(@RequestParam("id") Long id){

        JsonResult jsonResult = new JsonResult();

        RecycleOrderShowVo recycleOrderShowVo = recycleOrderService.findRecycleOrderDetailById(id);
        jsonResult.setCode("200");
        jsonResult.setData(recycleOrderShowVo);
        return jsonResult.getDataMap();
        //查询单个订单订单
    }

    @PostMapping("/updateOrder")
    @ApiOperation("订单入库")
    public Map updateOrder(@RequestParam("id") Long id, @RequestParam("state")String state){

        Recycleorder recycleorder=new Recycleorder();
        recycleorder.setId(id);
        recycleorder.setState(state);
        JsonResult jsonResult = new JsonResult();
        recycleOrderService.updateRecycleOrder(recycleorder);
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }
}
